package com.itheima.web.controller;

import com.itheima.domain.Comment;
import com.itheima.domain.Movies;
import com.itheima.service.CommentService;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/single")
public class SingleController {

    @Autowired
    private MoviesService moviesService;

    //查询影视详情数据
    @GetMapping("/findMoviesById")
    public Movies findMoviesById(Integer id){
        Movies movies = moviesService.findById(id);
        return movies;
    }

    @Autowired
    private CommentService commentService;

    //查询影视关联的评论列表
    @GetMapping("/findCommentByMoviesId")
    public List<Comment> findCommentByMoviesId(Integer moviesId){
        List<Comment> commentList = commentService.findCommentByMoviesId(moviesId);
        return commentList;
    }

    //完成添加评论功能
    @PostMapping("/saveComment")
    public String saveComment(@RequestBody Comment comment){
        //组装页面没有提交的数据
        comment.setTime(new Date());
        comment.setCreatorName("匿名");
        commentService.saveComment(comment);
        return "ok";
    }
}
